<?php
    namespace Npfe\Controller;
    use think\Controller;
    class GdcController extends Controller{
        function Showgd(){
            $this->display('djgd');
        }
        function Showsmj(){
            $this->display('djsmj');
        }
        public function listgd($mode){
            $posti = $_POST;
            $gdc = new \Npfe\Model\GlxqModel();
            $items = array();
            $dmt = \Npfe\Controller\MainController::getdmt();
            $data;
            switch ($mode) {
                case 1:
                    $sql = "gdlbvalue != '激活卡申请' && time >= '$dmt[dmtb]' and time <= '$dmt[dmte]'";
                    if (!empty($posti['lxnumber'])) {
                        $sql = "gdlbvalue != '激活卡申请' && contactnumber = '$posti[lxnumber]'";
                    }elseif (!empty($posti['starttime'])) {
                        $formated = \Npfe\Controller\MainController::formattime($posti['starttime'], $posti['endtime']);
                        $sql = "gdlbvalue != '激活卡申请' && time >= '$formated[stt]' && time <= '$formated[ett]'";
                    };
                    $data = $gdc->where($sql)->select();
                    break;
                case 2:
                    $sql = "gdlbvalue = '激活卡申请' && time >= '$dmt[dmtb]' and time <= '$dmt[dmte]'";
                    if (!empty($posti['lxnumber'])) {
                        $sql = "gdlbvalue = '激活卡申请' && contactnumber = '$posti[lxnumber]'";
                    }elseif (!empty($posti['starttime'])) {
                        $formated = \Npfe\Controller\MainController::formattime($posti['starttime'], $posti['endtime']);
                        $sql = "gdlbvalue = '激活卡申请' && time >= '$formated[stt]' && time <= '$formated[ett]'";
                    };
                    $data = $gdc->where($sql)->select();
                    break;
            }
            foreach($data as $row){
                $row['content']='<a href="javascript:void(0)" onclick="fsshowgdcl(\''.$row['contactnumber'].'\',\''.$row['time'].'\')">快速处理</a>';
                $row['hhj']=$row['hhj']=="true"?"是":"否";
                $row['hff']=$row['hff']=="true"?"是":"否";
                array_push($items, $row);
            }
            $value =array(
                "total" => count($items),
                'rows' => $items
            );
            $nonetr = json_encode($value);
            echo $nonetr;
        }
        function viewgd($cn,$time){
            $gdcd = new \Npfe\Model\GlxqModel();
            $data = $gdcd->where("contactnumber='$cn' AND time='$time'")->find();
            $table_change=array(
                'content' => $data['content'],
                'orderman' => $data['orderman'],
                'isend' => $data['isend'],
                'archivecontent' => $data['archivecontent'],
                'ctrlman' => $data['ctrlman'],
                'customername' => $data['customername'],
                'submitnumber' => $data['submitnumber'],
                'contactnumber' => $data['contactnumber'],
                'idnumber' => $data['idnumber'],
                'idcardaddress' => $data['idcardaddress'],
                'qctr' =>$this->getlinkqc($cn),
                'cn' => $cn,
                'time' =>$time,
                'hjtr' =>$this->serachhj($cn),
            );
            $this->assign($table_change);
            $this->display('viewgd');
        }
        function showinprogress($cn,$time){
            $now_em = session('nickname');
            //$gdclroot=$ROOT->cigdcl($_SESSION['uid']);  获取修改处理权限
            $gd = new \Npfe\Model\GlxqModel();
            $res = $gd->where("contactnumber = '$cn' && time = '$time'")->find();
            $table_change=array(
                'cn' => $cn,
                'time' => $time,
                'now_em' => $now_em,
                'archivecontent' => $res['archivecontent']
            );
            $this->assign($table_change);
            $this->display('npfe_tpl_sips');

        }
        function sumbitgdpg($cn,$time){
            $gd = new \Npfe\Model\GlxqModel();
            $xml = '<div id="gdc"><div class="vbr">工單處理</div>目前没有完成，数据库可能异常，请重新查询！</div>';
            $res = $gd->where("contactnumber='$cn' AND time='$time'")->find();
            if($res != false){
                $data = array(
                    'ctrlman'=> I('post.chuliren'),
                    'isend'=> I('post.gdlb'),
                    'endtime'=> date('Y-m-d H:i:s',time()),
                    'archivecontent' => I('archivecontent'),
                    'gdqc'=> I('post.gdqc'),
                    'xsygs'=> I('post.xsygs')
                );
                $gd->where(" contactnumber='$cn' AND time='$time'")->save($data);
                $xml = '<div id="gdc"><div class="vbr">工單處理</div>完成，你目前的工单已处理，请重新查询！</div>';  
            }else{
                $xml = '<div id="gdc"><div class="vbr">工單處理</div>目前没有完成，可能此数据已删除或异常，请重新查询！</div>';  
            }
            echo $xml;
        }
        function serachhj($cn){
            $df = '<tr><td>无</td><td>无</td><td>无</td><td>无</td><td>无</td><td>无</td><td>无</td><td>无</td><td>无</td><td>无权</td></tr>';
            $xml = '';
            $pgd = new \Npfe\Model\PgModel();
            $data = $pgd->where("gd_cn = '$cn'")->select();
            foreach($data as $row){
                $xml=$xml.'<tr><td>'.$row['pg_name'].'</td><td>'.$row['pg_begintime'].'</td><td>'.$row['pg_rechtime'].'</td><td>'.$row['pg_yjbx'].'</td><td>'.$row['pg_sjbx'].'</td><td>'.$row['traceman'].'</td><td>'.$row['oman'].'</td><td>'.$row['bz'].'</td><td>'.$row['bh'].'</td><td><a href="javascript:void(0)" onclick="updatehj(\''.$cn.'\',\''.$row['pg_begintime'].'\')">更正</a></td></tr>';
            }
            if($xml==''){
                $xml = $df;
            }
            return $xml;
        }
        function getlinkqc($cn){
            $xml = '';
            $qcd = new \Npfe\Model\Qcxq2Model();
            $data = $qcd->where("checknumber='$cn'")->select();
            foreach ($data as $row) {
                $row = $db->GetFetchArray();
                $xml=$xml.'<tr><td>'.$row['hwyname'].'</td><td>'.$row['clname'].'</td><td>'.$row['headman'].'</td><td>'.$cn.'</td><td>'.$row['sn'].'</td><td><a href="'.$row['link'].'" target="new">链接</a></td><td>'.$row['baseappraise'].'</td></tr>';
            }
            if($xml==''){
                $xml = '<tr><td>无</td><td>无</td><td>无</td><td>'.$cn.'</td><td>无</td><td>无</td><td>无</td></tr>';
            }
            return $xml;
        }
    }
?>
